import {  UserProfilesAPI } from "@/request/api"
// 用户信息api
export default {
  namespaced: true,
  state: {
    // 用户信息
    userInfo: {
      nickName: "玩家",
      coin: 0,
      headImg: require("@/assets/img/user.png")
    }
  },
  mutations: {
    changeUserInfo(state, payload) {
      // 用户信息
      state.userInfo = payload.userInfo
    },
    initUserInfo(state) {
      state.userInfo = {
        nickName: "玩家",
        coin: 0,
        headImg: require("@/assets/img/user.png")
      }
    }
  },
  actions: {
    async asyncChangeUserInfo({ commit }) {
      let userInfoRes = await UserProfilesAPI();
      // console.log("userInfoRes为:", userInfoRes);
      commit("changeUserInfo", userInfoRes.data)
    }
  },
}